<template>
  <div class="PlayList">
    <h1>经典</h1>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="item in playlistData" :key="item.tid">
          <div class="cover-num">
            <img :src="item.cover_url_small" />
            <span>{{ (item.access_num / 10000) | numFilter(1) }}万</span>
          </div>
          <span>{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";
import axios from "axios";
export default {
  data() {
    return {
      value: "",
      playlistData: [],
    };
  },

  created() {
    this.getBanner();
  },

  methods: {
    getBanner() {
      axios
        .get("/api/recommend/playlist?id=59")
        .then((res) => {
          // console.log(res.data.data.list);
          this.playlistData = res.data.data.list;
          this.betterScrollHorizontal(this.playlistData.length, 160);
        })
        .catch((err) => {
          console.error(err);
        });
    },

    betterScrollHorizontal(num, itemWidth) {
      let width = num * itemWidth;
      this.$refs.content.style.width = width + "px";
      this.$nextTick(() => {
        this.scroll = new BScroll(this.$refs.wrapper, {
          click: true,
          startX: 0,
          scrollX: true, //横向为true
          scrollY: false,
        });
      });
    },
  },

  mounted() {},

  filters: {
    numFilter(value, num) {
      return parseFloat(value).toFixed(num);
    },
  },
};
</script>

<style scoped>
.PlayList {
  width: 90%;
  margin: 0 auto;
  font-size: 18px;
  text-align: left;
}
.wrapper {
  width: 100%;
  overflow: hidden;
}
ul.content > li {
  width: 160px;
  display: inline-block;
  text-align: center;
  vertical-align: top;
}
ul.content > li img {
  width: 90%;
  border-radius: 20px;
}
.ul.content > li > span {
  display: block;
  width: 90%;
  margin: 0 auto;
  font-size: 12px;
}
.cover-num {
  position: relative;
}
.cover-num > span {
  display: block;
  position: absolute;
  right: 10px;
  bottom: 5px;
  z-index: 100;
  background-color: gray;
  border-radius: 20px;
  width: 100px;
}
</style>
